package com.hksj.wmp.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.base.query.AlarmQuery;
import com.hksj.base.query.BaseSpecialityQuery;
import com.hksj.base.service.DefaultAlarmService;
import com.hksj.base.vo.AlarmRecordVO;
import com.hksj.common.core.model.Rest;
import com.hksj.wmp.query.BaseAlarmQuery;
import com.hksj.wmp.service.WeChatAlarmService;
import com.hksj.wmp.vo.CurrentAlarmDeviceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author zengke
 * @version 1.0
 * @see WeChatAlarmController
 * @since 2024/10/14 17:54
 */

@Api(tags = "微信小程序-报警中心管理")
@RequestMapping("/api/wx/wechatAlarm")
@RestController
public class WeChatAlarmController {

    @Autowired
    private WeChatAlarmService wechatAlarmService;

    @Autowired
    private DefaultAlarmService defaultAlarmService;


    @ApiOperation(value = "报警首页-查询报警设备分布")
    @PostMapping("/queryAlarmDeviceDistribution")
    public Rest<List<Map<String, String>>> queryAlarmDeviceDistribution(@RequestBody BaseAlarmQuery query){
        List<Map<String, String>> distributionMap = wechatAlarmService.queryAlarmDeviceDistribution(query);
        return Rest.ok(distributionMap);
    }
    
    @ApiOperation(value = "报警首页-查询报警次数情况(本月、本周、本日报警统计)")
    @PostMapping("/queryAlarmFrequencySituation")
    public Rest<Map<String,String>> queryAlarmFrequencySituation(@RequestBody BaseSpecialityQuery query){
        Map<String, String> alarmFrequencyMap = wechatAlarmService.queryAlarmFrequencySituation(query);
        return Rest.ok(alarmFrequencyMap);
    }

    @ApiOperation(value = "报警首页-报警次数详情(每个专业的报警数量统计)")
    @PostMapping("/queryAlarmFrequencyDetail")
    public Rest<List<Map<String,String>>> queryAlarmFrequencyDetail(@RequestBody BaseAlarmQuery query){
        List<Map<String,String>> alarmFrequencyDetailList = wechatAlarmService.queryAlarmFrequencyDetail(query);
        return Rest.ok(alarmFrequencyDetailList);
    }

    @ApiOperation(value = "报警明细-查询报警记录",response = AlarmRecordVO.class)
    @PostMapping("/queryAlarmRecordListByPaging")
    public Rest<Page<AlarmRecordVO>> queryAlarmRecordListByPaging(@RequestBody @Validated AlarmQuery query){
        Page<AlarmRecordVO> page = defaultAlarmService.pageAlarmHistory(query);
        return Rest.ok(page);
    }

    @ApiOperation(value = "报警明细-查询当前报警设备列表",response = CurrentAlarmDeviceVO.class)
    @PostMapping("/queryCurrentAlarmDeviceListByPaging")
    public Rest<IPage<CurrentAlarmDeviceVO>> queryCurrentAlarmDeviceListByPaging(@RequestBody BaseSpecialityQuery query){
        IPage<CurrentAlarmDeviceVO> page = wechatAlarmService.queryCurrentAlarmDeviceListByPaging(query);

        return Rest.ok(page);
    }
}
